package demoMod.stsconsole.powers;

import demoMod.stsconsole.ConsoleEntry;
import demoMod.stsconsole.cards.AbstractCard;
import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.commands.Use;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.interfaces.TurnEndSubscriber;
import demoMod.stsconsole.interfaces.UseCardSubscriber;

public class DoubleTapPower extends AbstractPower implements UseCardSubscriber, TurnEndSubscriber {
    public static final String ID = "DoubleTapPower";
    private int playTimes;

    public DoubleTapPower(AbstractCreature owner, int amount) {
        super(ID, owner, amount);
        this.playTimes = 2;
    }

    @Override
    public void stackAmount(int[] amount) {
        super.stackAmount(amount);
        this.playTimes = 2;
    }

    @Override
    public String getUpdatedDescriptions() {
        return String.format(this.description, this.amount[0]);
    }

    @Override
    public void atEndOfTurn(boolean isPlayer) {
        if (this.owner instanceof AbstractPlayer == isPlayer) {
            this.onRemove();
        }
    }

    @Override
    public void preUseCard(AbstractCard card) {

    }

    @Override
    public void postUseCard(AbstractCard card) {
        if (card.type == AbstractCard.CardType.ATTACK) {
            --this.playTimes;
            if (this.playTimes <= 0) {
                this.amount[0]--;
                this.playTimes = 2;
                if (this.amount[0] <= 0) {
                    this.onRemove();
                }
            } else {
                new Use().execute(new String[]{"card", Integer.toString(AbstractDungeon.player.hand.indexOf(card))}, ConsoleEntry.getScanner());
            }
        }
    }
}
